<!DOCTYPE html>
<html>
	<head>
		<meta charset="{CHARSET}">
		<title>提供一个中文汉字Unicode互转、 ASCII与Unicode互转的在线工具</title>
		<style>
			textarea {
			 width: 100%;
			 height: 200px;
			 resize:vertical;
			 border: 1px solid #CCC;
			 /*border-radius:8px;*/
			 padding:4px;
			 box-shadow: 2px 2px 5px #d3d6da;
			 -moz-box-shadow: 2px 2px 5px #d3d6da;
			}
		</style>
	</head>
	<body>		
	<div class='divider'>中文汉字Unicode互转、 ASCII与Unicode互转的在线工具</div>
      	<textarea id="input_area" name="input_area" placeholder="贴入要处理的Unicode或Ascii字符" value=""></textarea>
            <div class='row'>
                <button onclick="javascript:a('CONVERT_FMT2');">中文汉字转Unicode</button>
                <button onclick="javascript:a('RECONVERT');">Unicode转中文汉字</button>      
                <button onclick="javascript:a('RECONVERT')">ASCII转换Unicode</button>
                <button onclick="javascript:a('CONVERT_FMT3');">Unicode转换ASCII</button>
                <button onclick="javascript:a('CONVERT_FMT1');">中文转换&#XXXX</button>
   			</div>
		<textarea name="output_area" id="output_area" onclick="this.select();" placeholder="处理之后的Unicode或Ascii字符" value=""></textarea>
	</body>
</html>
<script type="text/javascript">
        function a(pChoice){
            var inputEle = document.getElementById('input_area');
            var outputEle = document.getElementById('output_area');
            switch(pChoice){ 
                case "CONVERT_FMT1":
                    outputEle.value = ascii(inputEle.value);
                    break; 
                case "CONVERT_FMT2":
                    outputEle.value = unicode(inputEle.value);
                    break; 
                case "CONVERT_FMT3":
                    outputEle.value = unicode1(inputEle.value);
                    break; 
                case "RECONVERT":
                    outputEle.value = reconvert(inputEle.value);
                    break; 
            } 
        } 
        function ascii(str){ 
            var value='';
            for (var i = 0; i < str.length; i++) {
                value += '\&#x' + left_zero_4(parseInt(str.charCodeAt(i)).toString(16))+';';
            }
            return value;
        } 
        function unicode(str){
            var value='';
            for (var i = 0; i < str.length; i++) {
                value += '\\u' + left_zero_4(parseInt(str.charCodeAt(i)).toString(16));
            }
            return value;
        }
        function left_zero_4(str) {
            if (str != null && str != '' && str != 'undefined') {
                if (str.length == 2) {
                    return '00' + str;
                }
            }
            return str;
        }
        function unicode1(str){ 
            var value='';
            for (var i = 0; i < str.length; i++)
                value += '&#' + str.charCodeAt(i) + ';';
            return value;
        } 
        function reconvert(str){ 
            str = str.replace(/(\\u)(\w{1,4})/gi,function($0){ 
                return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{1,4})/g,"$2")),16))); 
            }); 
            str = str.replace(/(&#x)(\w{1,4});/gi,function($0){ 
                return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{1,4})(%3B)/g,"$2"),16)); 
            }); 
            str = str.replace(/(&#)(\d{1,6});/gi,function($0){ 
                return String.fromCharCode(parseInt(escape($0).replace(/(%26%23)(\d{1,6})(%3B)/g,"$2"))); 
            }); 
             
            return str; 
        }
</script>
<!--感谢脚本之家提供的技术支持-->
<!--仅仅个人使用-->